<script setup lang="ts">
import { reactive } from "vue";
import { storageSession } from "/@/utils/storage";
import info, { ContextProps } from "../components/ReInfo/index.vue";
import { initRouter } from "/@/router";
import { Login } from "/@/api/auth"
import { useRouter } from "vue-router"
import { IResponseLogin } from "../api/interface";
import { ElMessage } from "element-plus";
import { resolveCname } from "dns";
const router = useRouter();
const contextInfo: ContextProps = reactive({
  userName: "",
  passWord: ""
});

// 登录
const onLogin = () => {
  Login<IResponseLogin>({
    username: contextInfo.userName,
    password: contextInfo.passWord
  }).then(res => {
    // console.log(res)
      storageSession.setItem("info", {
        username: res.data.name,
        accessToken: res.data.token
      });
      initRouter(res.data.name).then(() => {});
      router.push("/");
  }).catch(e => {
    console.log(e)
  })
};
</script>

<template>
  <div class="login">
    <info :ruleForm="contextInfo" @on-behavior="onLogin" />
  </div>
</template>
